home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 6 / MacMania 6.toast / / Multimedia & Desktop / sk8 / SK8InJava / Code / Object System / Symbol.java < prev   
Encoding:
Java Source  |  1997-02-27  |  1.2 KB  |  44 lines  |  [TEXT/CWIE]

  1. /*  SK8 © 1997 Apple Computer, Inc.
  2.     This code is protected under the current SK8 License
  3.     See http://sk8.research.apple.com/ for more information
  4.     Apple Research Laboratories
  5. */
  6.  
  7. import java.util.Hashtable;
  8.  
  9. class symbol {
  10.     static Hashtable SymbolTable = new Hashtable();
  11.     public String name;
  12.     
  13.     public symbol(String nameForSym) {
  14.         //Check if a symbol with this name already exists
  15.         String newName = nameForSym.toUpperCase();
  16.         Object oldsym = SymbolTable.get(newName);
  17.         if (oldsym != null) 
  18.             //should probably be throwing an exception here!
  19.             sk8.sendtolog ("WARNING: REDEFINING AN EXISTING SYMBOL!" + newName);
  20.         
  21.         //here we take our new symbol, fill out it's name field and put it in our table.
  22.         this.name = newName;
  23.         SymbolTable.put(newName, this);
  24.     }
  25.     
  26.     public String name() {
  27.         return this.name;
  28.     }
  29.  
  30.     //this is the standard function which will take a string and return
  31.     //the corresponding symbol.  If a symbol of that name does not already exist
  32.     //it creates one.
  33.     static public symbol getsymbol(String nameForSym) {
  34.         symbol existingSym = (symbol)SymbolTable.get(nameForSym);
  35.         if (existingSym == null)
  36.             return new symbol(nameForSym);
  37.         else
  38.             return existingSym;
  39.     }
  40.  
  41.     public String toString(){
  42.         return name();
  43.     }
  44. }